package com.gduf.lsm.controller;

import com.gduf.lsm.common.Result;
import com.gduf.lsm.entity.ApplyNum;
import com.gduf.lsm.pojo.dto.ApplyStatusDTO;
import com.gduf.lsm.service.ApplyNumService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户数据申请表前端操作接口
 **/
@RestController
@RequestMapping("/applyNum")

public class ApplyNumController {

    @Resource
    private ApplyNumService applyNumService;

    /**
     * 新增
     * @param applyNum
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ApplyNum applyNum) {
        applyNumService.add(applyNum);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        applyNumService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        applyNumService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     * @param applyNum
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody ApplyNum applyNum) {
        applyNumService.updateById(applyNum);
        return Result.success();
    }

    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody ApplyStatusDTO applyStatusDTO){
        applyNumService.updateStatus(applyStatusDTO);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ApplyNum applyNum = applyNumService.selectById(id);
        return Result.success(applyNum);
    }

    /**
     * 查询所有
     * @param applyNum
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(ApplyNum applyNum ) {
        List<ApplyNum> list = applyNumService.selectAll(applyNum);
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param applyNum
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(ApplyNum applyNum,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "15") Integer pageSize) {
        PageInfo<ApplyNum> page = applyNumService.selectPage(applyNum, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 申请员的分页查询
     * @param applyNum
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPageApply")
    public Result selectPageApply(ApplyNum applyNum,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "15") Integer pageSize) {
        PageInfo<ApplyNum> page = applyNumService.selectPageApply(applyNum, pageNum, pageSize);
        return Result.success(page);
    }
}